'use strict';

var express = require('express');
var Primus = require('primus');
var http = require('http');
var path = require('path');
var app = express();

var server = require('http').createServer(app)


app.get('/', function(req, res) {
  res.sendfile(__dirname + '/index.html');
});
//
// Attach Primus to the HTTP server.
//
var primus = new Primus(server, {pathname: '/chatops/api/v2/chat/snapper/socket/', transformer: "engine.io"});

// primus.library()
primus.save(__dirname + '/chatops/primus.js')

app.use('/chatops', express.static(__dirname + '/chatops'));

//
// Listen for connections and echo the events send.
//
primus.on('connection', function connection(spark) {
  spark.on('data', function received(data) {
    console.log(spark.id, 'received message:', data);
    spark.write(data);
  });
});

server.listen(8080, function () {
  console.log('Open http://localhost:8080 in your browser');
});